package dao

import (
	"yundian/internel/app/models/rostersetting"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
)

type RosterSettingDao struct {
}

func NewRosterSettingDao() *RosterSettingDao {
	return &RosterSettingDao{}
}

func (dao *RosterSettingDao) GetRosterList(rosterType int) *dingo.ErrorWrap {

	var lst []*rostersetting.RosterSetting

	db := global.Orm.Table("roster_setting")

	if rosterType > 0 {
		db.Where("type = ?", rosterType)
	}

	db.Find(&lst)

	return dingo.ErrorIf(db.Error, lst)

}

func (dao *RosterSettingDao) UpdateRoster(rosterModel *rostersetting.RosterSetting) *dingo.ErrorWrap {
	db := global.Orm.Table("roster_setting").Where("id = ?", rosterModel.Id).Model(&rosterModel).Updates(rosterModel)
	return dingo.ErrorIf(db.Error, true)
}
